import { watcher } from "@feng3d/watcher";
import { TorusGeometry } from "../../thirdparty/three/imports";
import { BufferGeometry3D } from "../core/BufferGeometry3D";

export class TorusGeometry3D extends BufferGeometry3D
{
    radius = 1;
    tube = 0.4;
    radialSegments = 12;
    tubularSegments = 48;
    arc = Math.PI * 2;

    get _geometry()
    {
        if (!this.__geometry)
        {
            this.__geometry = new TorusGeometry(this.radius, this.tube, this.radialSegments, this.tubularSegments, this.arc);
        }

        return this.__geometry;
    }
    declare protected __geometry: TorusGeometry;

    constructor()
    {
        super();
        watcher.watchs(this as TorusGeometry3D, ["radius", "tube", "radialSegments", "tubularSegments", "arc"], this._invalidate, this);
    }

    destroy()
    {
        watcher.unwatchs(this as TorusGeometry3D, ["radius", "tube", "radialSegments", "tubularSegments", "arc"], this._invalidate, this);
    }
}
